<template>
  <div>
    <div class="warnningTip"><i class="el-icon-warning-outline" />开启自动返佣，系统会在返佣发放天数后，自动处理返佣发放；关联有效期：是指用户关联返佣人员的有效期天数，绑定的有效期天数以绑定时配置的时间为准；</div>
    <el-form
      ref="form"
      class="doumee-form"
      :model="param"
      :rules="rules"
      label-width="150px"
      label-suffix="："
    >
      <el-form-item label="小程序名称" prop="appName">
        <el-input
          v-model="param.appName"
          class="w400"
          type="text"
          placeholder="请输入小程序名称"
          maxlength="20"
        />
      </el-form-item>
      <el-form-item label="关联有效期(天)" prop="relevanceDay">
        <el-input
          v-model="param.relevanceDay"
          class="w400"
          oninput="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
          type="text"
          placeholder="请输入关联有效期"
          maxlength="20"
        />
      </el-form-item>
      <el-form-item label="开启自动返佣" prop="sendType">
        <el-switch v-model="param.sendType" />
      </el-form-item>
      <el-form-item v-if="param.sendType" label="返佣发放天数(天)" prop="receiptDay">
        <el-input
          v-model="param.receiptDay"
          oninput="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
          class="w400"
          type="text"
          placeholder="请输入返佣发放天数"
          maxlength="20"
        />
      </el-form-item>
      <el-form-item>
        <el-button v-if="meta.indexOf('changeSetInfo') > -1" :loading="subLoading" type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { changeSetInfo, SetInfo } from '@/api'
import { rules } from './config'
export default {
  props: {
    meta: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      param: {},
      rules,
      subLoading: false
    }
  },
  created() {
    this.getSetInfo()
  },
  methods: {
    onSubmit() {
      const param = { ...this.param }
      param.sendType = param.sendType ? 1 : 0
      if (param.sendType === 0) {
        param.receiptDay = ''
      }
      // subLoading
      this.$refs['form'].validate((valid) => {
        if (valid) {
          changeSetInfo({ param }).then(res => {
            if (res.errorCode !== '000000') return
            this.$message.success('提交成功')
            this.getSetInfo()
          })
        }
      })
    },
    getSetInfo() {
      SetInfo({ param: {}}).then(res => {
        this.param = { ...res.record }
        this.param.sendType = this.param.sendType === '1'
      })
    }
  }
}
</script>

<style>

</style>
